package com.wits.qso.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.springframework.format.annotation.DateTimeFormat;

import com.wits.platform.entity.BaseEntity;

/**
 * 我的课程类（表示学生注册的课程）
 * 
 */
@Entity
@Table(name = "qso_course_register")
public class MyRegisterCourse extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7504415901424810189L;

	/** 课程注册编号 **/
	private String id;

	/**
	 * 学生
	 */
	private Student student;
	/**
	 * 课程
	 */
	private Course course;

	/**
	 * 教师
	 */
	private Teacher teacher;
	/**
	 * 申请状态
	 */
	private String crStatus;

	/**
	 * 申请说明
	 */
	private String crMessage;

	/** 申请日期 **/
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date applyDate;

	/** 批准日期 **/
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date authDate;

	@Id
	@GenericGenerator(name = "idGen", strategy = "com.wits.platform.common.id.generator.IDGenerator", parameters = {
			@Parameter(name = "segment_value", value = "QSO_CR_ID"),
			@Parameter(name = "table_name", value = "wits_id_generator"),
			@Parameter(name = "value_column_name", value = "gen_value"),
			@Parameter(name = "segment_column_name", value = "gen_name"),
			@Parameter(name = "segment_value_length", value = "10"),
			@Parameter(name = "sq_format", value = "%08d"),
			@Parameter(name = "sq_prefix", value = "RC") })
	@GeneratedValue(generator = "idGen")
	@Column(name = "cr_id", nullable = false, insertable = true, updatable = false, length = 10)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "stu_id", updatable = true)
	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	@ManyToOne
	@JoinColumn(name = "course_id", updatable = true)
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	@ManyToOne
	@JoinColumn(name = "ter_id", updatable = true)
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	@Column(name = "cr_status", length = 2)
	public String getCrStatus() {
		return crStatus;
	}

	public void setCrStatus(String crStatus) {
		this.crStatus = crStatus;
	}

	@Column(name = "cr_message", length = 200)
	public String getCrMessage() {
		return crMessage;
	}

	public void setCrMessage(String crMessage) {
		this.crMessage = crMessage;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_apply")
	public Date getApplyDate() {
		return applyDate;
	}

	public void setApplyDate(Date applyDate) {
		this.applyDate = applyDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_auth")
	public Date getAuthDate() {
		return authDate;
	}

	public void setAuthDate(Date authDate) {
		this.authDate = authDate;
	}

	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("{ ");
		buf.append("\"courseId\":\"").append(this.course.getId());
		buf.append("\",\"terId\":\"").append(this.teacher.getTerId());
		buf.append("\",\"terName\":\"").append(this.teacher.getTerName());
		buf.append("\",\"stuId\":\"").append(this.student.getStuId());
		buf.append("\",\"stuName\":\"").append(this.student.getStuName());
		buf.append("\",\"courseName\":\"").append(this.course.getTitle());
		buf.append("\" }");
		return buf.toString();
	}

	public String display() {
		return null;
	}

}
